package com.sikaryofficial.backend.utils;

import com.ip2location.IP2Location;
import com.ip2location.IPResult;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @author : qinjinyuan
 * @desc : IP 国家信息服务
 * @date : 2024/07/05 17:01
 */
@Slf4j
public class IP2LocationTest {

    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
            // 加载数据库
            IP2Location db = new IP2Location();
            db.Open("E:\\tmp\\IP2LOCATION-LITE-DB1.BIN");
            //  db.Open("E:\\tmp\\IP2LOCATION-LITE-DB3.BIN");
            // 查询 IP 地址
            try {
                IPResult record = db.IPQuery("45.61.227.194");
                log.info("Country: " + record.getCountryShort());
                log.info("Country: " + record.getCountryLong());
                log.info("record: " + record);
            } catch (Exception e) {
                e.printStackTrace();
            }
            // 关闭数据库
            db.Close();
        log.info("耗时：" + (System.currentTimeMillis() - start));
    }
}
